﻿package mortal.game.view.godLuckGift.panel
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.godLuckGift.data.*;
    import mortal.game.view.mainUI.zazen.*;

    public class GodLuckGiftCollectPanel2 extends RightDownShrinkView
    {
        protected var _timeDes:GBitmap;
        protected var _title:GTextFiled;
        protected var _timeTxt:GTextFiled;
        protected var _goldDes:GTextFiled;
        protected var _goldTxt:GTextFiled;
        protected var _coinDes:GTextFiled;
        protected var _coinTxt:GTextFiled;
        protected var _itemSp:CellsGridSprite;
        protected var _pageSelector:PageSelecter;
        private var _pageTool:PageTool;
        protected var _leftTime:SecTimerView;
        private var _giftLen:int = 5;
        private var _coin:int;
        private var _gold:int;
        private var _items:Array;
        private var _openDt:Date;
        private static var _instance:GodLuckGiftCollectPanel2;

        public function GodLuckGiftCollectPanel2(param1:String, param2:String)
        {
            super(param1, param2);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.godLuckGift, this.onResLoad);
            return;
        }// end function

        private function onResLoad() : void
        {
            this._timeDes = UIFactory.gBitmap(ImagesConst.GodLuckGoldCountDownTitle, 54, 48, _bodySprite);
            this._title = UIFactory.gTextField("" + Language.getString(71063), 73, 15, 200, 25, _bodySprite, GlobalStyle.textFormatHuang2.setSize(15).setBold(true));
            this._timeTxt = UIFactory.gTextField("15:30", 164, 45, 100, 20, _bodySprite, GlobalStyle.textFormatLv.setSize(13));
            this._goldDes = UIFactory.gTextField("" + Language.getString(71064), 9, 71, 80, 25, _bodySprite, GlobalStyle.textFormatAnjin.setSize(13).setBold(true));
            this._goldTxt = UIFactory.gTextField("568997", 74, 72, 100, 20, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13));
            this._coinDes = UIFactory.gTextField("" + Language.getString(71065), 146, 71, 100, 20, _bodySprite, GlobalStyle.textFormatAnjin.setSize(13).setBold(true));
            this._coinTxt = UIFactory.gTextField("12365", 212, 71, 100, 20, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13));
            this._itemSp = UIFactory.getUICompoment(CellsGridSprite);
            this._itemSp.colNum = 5;
            this._itemSp.vCellWid = 46;
            this._itemSp.hCellWid = 100;
            this._itemSp.genCellFun = this.getCell;
            this._itemSp.genCells(5);
            this._itemSp.x = 37;
            this._itemSp.y = 100;
            _bodySprite.addChild(this._itemSp);
            this._pageSelector = UIFactory.pageSelecter(110, 144, _bodySprite, PageSelecter.SingleMode);
            this._pageSelector.setbgStlye(ImagesConst.ComboBg, GlobalStyle.textFormatBai.center());
            this._pageSelector.maxPage = 1;
            this._pageSelector.pageTextBoxSize = 36;
            this._pageSelector.configEventListener(Event.CHANGE, this.onPageChange);
            this._giftLen = GodLuckGiftUtil.giftLen;
            this._pageTool = new PageTool([], this._giftLen);
            this._timeTxt.text = "";
            this._leftTime = UIFactory.secTimeView("" + Language.getString(71066), 148, 47, 80, 20, _bodySprite, GlobalStyle.textFormatHong.center());
            this._leftTime.timeOutHandler = this.timeCompl;
            this.updateInfo(this._coin, this._gold, this._items);
            this.updateOpenDt(this._openDt);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._timeDes = null;
            this._title = null;
            this._timeTxt = null;
            this._goldDes = null;
            this._goldTxt = null;
            this._coinDes = null;
            this._coinTxt = null;
            this._itemSp = null;
            this._pageSelector = null;
            this._pageTool = null;
            this._leftTime = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            var _loc_2:* = this._pageTool.getByPageNo(this._pageSelector.currentPage);
            this._itemSp.genCells(this._giftLen);
            this._itemSp.updateAllNotDispose(_loc_2, null, "itemData", false);
            return;
        }// end function

        private function timeCompl() : void
        {
            this._leftTime.stop();
            return;
        }// end function

        private function getCell(param1:Object = null) : BaseItem
        {
            var _loc_2:* = UIFactory.getUICompoment(BaseItem, 0, 0, _bodySprite);
            _loc_2.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            _loc_2.isDragAble = false;
            _loc_2.isShowLock = true;
            return _loc_2;
        }// end function

        public function updateInfo(param1:int, param2:int, param3:Array) : void
        {
            this._coin = param1;
            this._gold = param2;
            this._items = param3;
            if (this._coinTxt == null)
            {
                return;
            }
            this._coinTxt.text = "" + param1;
            this._goldTxt.text = "" + param2;
            if (param3)
            {
                this._pageTool.array = param3;
                this._pageSelector.maxPage = Math.ceil(param3.length / this._giftLen);
                this.onPageChange(null);
            }
            return;
        }// end function

        public function updateOpenDt(param1:Date) : void
        {
            this._openDt = param1;
            if (param1 == null || this._leftTime == null)
            {
                return;
            }
            var _loc_2:* = ClockManager.instance.nowDate;
            var _loc_3:* = (param1.time - ClockManager.instance.nowDate.time) / 1000;
            this._leftTime.visible = true;
            if (_loc_3 > 0)
            {
                this._leftTime.visible = true;
                this._leftTime.setLeftTime(_loc_3);
            }
            return;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function get instance() : GodLuckGiftCollectPanel2
        {
            if (_instance == null)
            {
                _instance = new GodLuckGiftCollectPanel2(null, null);
            }
            return _instance;
        }// end function

    }
}
